<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>修改志愿者服务</title>
  <script type="text/javascript" src="assets/dwz/ui/uploadify/scripts/jquery.uploadify.js"></script>
  <script type="text/javascript">
    $(function(){
      //初始化uploadify 用于word上传
      $("#uploadFile").uploadify({
        'swf' : 'assets/dwz/ui/uploadify/scripts/uploadify.swf',//上传的flash文件,必用
        'uploader' : 'community_image_service',//上传的请求URL
        'method' : "get",//请求方式
        'fileObjName' : 'fileName',//与后台Action中file属性一样
        'formData' : {
          'uploadUrl' : 'hangzhou/talent'
        },//附带值，参数
        'auto' : true,//自动上传
        'multi' : false,//是否为多文件上传
        'buttonImage':'assets/dwz/ui/uploadify/img/upload.png',
        'uploadLimit' : 112342,//一次可以上传多少个文件
        'fileSizeLimit' : '100000KB',//单个文件上传最大值
        'queueSizeLimit' : 100,//最多上传个数
        'successTimeout' : 99999,//上传超时时间
        'rollover' : true,
        'dataType':'text',
        'removeCompleted' : true,//上传完成后是否自动隐藏进度条
        onUploadSuccess : function(file,//每个文件上传完成后都会调用一次，其中data为，相应信息，file为上传文件信息,response只有两个值true or false
                                   data, response) {
            if( data == null ){
                alertErrorMessage("上传图片失败");
                return;
            }
            alertOkMessage( "上传成功！" );
            $(".edit_community_volunteer_form img").attr("src",data);
            $(".edit_community_volunteer_form input[name='imageUrl']").val(data);
        },
        onError : function() {
          alert("上传失败");
        }
      });
    })

    //全选/取消全选
    function checkedAllBlock(){
      var objChecked = $( ".edit-volunteer-form" ).find( "input[name='checkedAll']" ).attr( "checked" );
      if( objChecked == "checked" ){
        $(".edit-volunteer-form").find( "input[name='blockIds']").each(function(i,j){
          $(j).attr( "checked","checked" );
        })
      }else{
        $(".edit-volunteer-form").find( "input[name='blockIds']").each(function(i,j){
          $(j).removeAttr( "checked" );
        })
      }
    }

    //提交表单校验
    function checkEditVolunteer(){

      var id = "";
      $(".edit_community_volunteer_form").find( "input[name='blockIds']:checked").each(function(i,j){
          id += $(j).val() + ",";
      })
      if( id == "" ){
        alertMsg.warn('请选择小区！')
        return false;
      }
        id = id.substring( 0,id.length - 1 );
      var guideId = $(".edit_community_volunteer_form").find( "select[name='guideId']").val();
      if( guideId == -1 ){
        alertMsg.warn('请选择党政建设！');
        return false;
      }

      var imageUrl = $(".edit_community_volunteer_form").find( "input[name='imageUrl']").val();
      if( imageUrl == null || imageUrl == "" || imageUrl == "http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg" ){
          alertMsg.warn('请上传封面！')
          return false;
      }
      $(".edit_community_volunteer_form").find( "input[name='blockIdStr']").val( id );
      $(".edit_community_volunteer_form").submit();
      return true;
    }

    //错误提示
    function alertErrorMessage(word){
        alertMsg.error(word);
    }

    //成功提示
    function alertOkMessage(word){
        alertMsg.correct(word);
    }

    //删除图片
    $(".edit_community_volunteer_form .delete-this-pic").click(function () {
        $(".edit_community_volunteer_form img").attr("src","http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg");
        $(".edit_community_volunteer_form input[name='imageUrl']").val("");
    })
  </script>
</head>
<body>
<div class="page unitBox">
  <form method="post" action="save_edit_community_volunteer" class="pageForm required-validate edit_community_volunteer_form" onsubmit="return validateCallback(this, dialogAjaxDone)" novalidate="novalidate">
    <div class="pageContent">
      <div class="pageFormContent edit-volunteer-form" layouth="97">
        <dl>
          <dt>标题：</dt>
          <dd>
            <input type="text" maxlength="20" placeholder="最多只能输入20个汉字" name="buildTitle" class="required" value="${volunteer.buildTitle}"/>
          </dd>
        </dl>
        <dl style="height: 110px;">
          <dt>图片logo：</dt>
          <dd style="position:relative;">
            <img src="${image.imageUrl}" width="120px;" height="80px;"/>
            <input type="file" name="file" id="uploadFile" />
            <input type="hidden" name="imageUrl" value="${image.imageUrl}"/>
            <a style="background: rgba(0,0,0,0.5);display:block;position:absolute;top:0;left:86px;pediting:5px;text-align: center;color:#fff;" class="delete-this-pic">删除</a>
          </dd>
        </dl>
        <dl style="height: 110px;">
          <dt>指南内容：</dt>
          <dd>
            <textarea placeholder="最多只能输入500个汉字" name="buildContent" class="required" cols="35" rows="5">${volunteer.buildContent}</textarea>
          </dd>
        </dl>
        <dl style="height: auto;">
          <dt>所属小区：</dt>
          <dd>
            <input type="hidden" name="blockIdStr"/>
            <%--<input type="checkbox" name="checkedAll" onclick="checkedAllBlock();"/>全选<br>--%>
            <c:forEach var="block" items="${blocks}">
              <input type="checkbox" onclick="return false" value="${block.id}" name="blockIds" checked/>${block.blockName}<br>
            </c:forEach>
            <%--<c:forEach var="blockNot" items="${blockNots}">--%>
              <%--<input type="checkbox" value="${blockNot.id}" name="blockIds"/>${blockNot.blockName}<br>--%>
            <%--</c:forEach>--%>
          </dd>
        </dl>
      </div>
      <input type="hidden" value="${volunteer.id}" name="id"/>
      <div class="formBar">
        <ul>
          <li>
            <div class="buttonActive">
              <div class="buttonContent">
                <button type="button" onclick="return checkEditVolunteer();">保存</button>
              </div>
            </div>
          </li>
          <li>
            <div class="button">
              <div class="buttonContent">
                <button class="close" type="button">关闭</button>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </form>
</div>
</body>
</html>
